#include<bits/stdc++.h>
#define jss301 return
#define ll long long
using namespace std;

int T;

int main()
{
    freopen("detect.in","r",stdin);freopen("detect.out","w",stdout);
    cin>>T;while(T--){
        bool cam[100000];memset(cam,0,sizeof(cam));
        bool closecam[100000];
        memset(closecam,1,sizeof(closecam));
        //chao su che liang
        int n,m,l,vvv,car1=0;cin>>n>>m>>l>>vvv;
        int d,v,a,speed[n],delta[n],deltai=0,wherecamera[l];
        memset(wherecamera,0,sizeof(wherecamera));
        memset(delta,0,sizeof(delta));
        for(int i=0;i<n;i++){
           cin>>d>>v>>a; 
           if(a==0 and v<=vvv) car1++;
           else if((3*3-v*v)*1.0/(2*a)*1.0+d<=n){
               car1++;
               delta[deltai]=(3*3-v*v)*1.0/(2*a)*1.0;
               deltai++;
           }
           
        }
        cout<<"okkkk"<<endl;
        // return 0;
        int temp;while(temp!=l){
            cin>>temp;
            cam[temp]=1;
            cam[l]=1;
        }
        cout<<"okkkk"<<endl;
        // sort(delta,delta+deltai);
        for(int i=0;i<deltai;i++){
            // 1 5 5 15 3 0 3 0 12 4 0 1 1 4 5 5 -2 6 4 -4
            if(delta[i]+d<l){
                int temp;
                for(int j=0;j<l;j++){
                    if(wherecamera[j]) {
                        temp=j;
                        break;
                    }
                }
                closecam[temp]=0;
            }
            
        }cout<<"okkkk"<<endl;
        // cout<<"okkkk"<<endl;
        int cnt=0;
        for(int i=0;i<100000;i++){
            if(closecam[i]==0) cnt++;
        }
        cout<<car1<<" ";
        cout<<cnt<<endl;
    }
    fclose(stdin);fclose(stdout);
    jss301 0;
}
